VC++的菜鸟问题`大侠们来``

来源:百度知道 编辑:UC知道 时间:2024/05/21 09:23:05
LRESULT CALLBACK WinWsProc( //这里的CALLBACK
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

第一行的CALLBACK是什么意思,又有什么作用? 最好能具体说明一下```谢谢了``

首先看MSDN里给出的解释

CALLBACK
·Use in place of FAR PASCAL in application callback routines such as window procedures and dialog procedures.

再看看到底这两个宏的内容是什么吧

VC:WINDEF.h
#define CALLBACK PASCAL //=_pascal,VC已经不支持直接使用_pascal了
#define WINAPI CDECL //=_cdecl

BCB:windef.h
#define CALLBACK __stdcall
#define WINAPI __stdcall

引出了cdecl stdcall等一些可能很少见的关键字

那么cdecl、pascal、stdcall、fastcall等修饰符号到底什么意思呢?
非常简单,就是关于堆栈的一些说明,首先是函数参数压栈顺序,其次是
压入堆栈的内容由谁来清除,调用者还是函数自己?
这些开关用来告诉编译器产生什么样的汇编代码。

下面把区别列表如下:

Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
pascal Left-to-right Routine No
cdecl Right-to-left Caller No
stdcall Right-to-left Routine No
safecall Right-to-left Routine No

简单说明:

__cdecl是C/C++和MFC程序默认使用的调用约定,也可以在函数声明时加上__cdecl关键字来手工指定。采用__cdecl约定时,函数参数按照从右到左的顺序入栈,并且由调用函数者把参数弹出栈以清理堆栈。因此